
#include "myplane.h"
#include "config.h"
myplane::myplane()
{

    m_plane.load(":/ph/images/hero1.png");
    m_x=(GAME_WINDTH-m_plane.width())*0.5;
    m_y=GAME_HEIGHT-m_plane.height();

    m_rect.setWidth(m_plane.width());
    m_rect.setHeight(m_plane.height());

    m_rect.moveTo(m_x,m_y);

}
void myplane::shoot()
{
    //lei ji jian ge
    m_recorder++;

    if(m_recorder<BULLET_TIMEX)
    {
        return;
    }
    m_recorder=0;

    for(int i=0;i<BULLET_NUM;i++)
    {
        if(m_bullets[i].m_free)
        {
            m_bullets[i].m_free=false;

            m_bullets[i].m_x=m_x+m_rect.width()*0.5-3;
            m_bullets[i].m_y=m_y;
            break;
        }
    }
    for(int i=0;i<BULLET_NUM;i++)
    {
        if(m_bullets[i].m_freea)
        {
            m_bullets[i].m_freea=false;

            m_bullets[i].m_xa=m_x+m_rect.width()*0.7;
            m_bullets[i].m_ya=m_y-10;
            break;
        }
    }
    for(int i=0;i<BULLET_NUM;i++)
    {
        if(m_bullets[i].m_freeb)
        {
            m_bullets[i].m_freeb=false;

            m_bullets[i].m_xb=m_x+m_rect.width()*0.3;
            m_bullets[i].m_yb=m_y-10;
            break;
        }
    }


}

void myplane::shoota()
{
    m_recordera++;
    if( m_recordera<BULLET_TIMEX)
    {
        return;
    }
    m_recordera=0;
    for(int i=0;i<BULLET_NUM;i++)
    {
        if(m_bullets[i].m_freea)
        {
            m_bullets[i].m_freea=false;

            m_bullets[i].m_xa=m_x+m_rect.width()*0.7;
            m_bullets[i].m_ya=m_y-10;
            break;
        }
    }

}
void myplane::shootb()
{
    m_recorderb++;
    if( m_recorderb<BULLET_TIMEX)
    {
        return;
    }
    m_recorderb=0;
    for(int i=0;i<BULLET_NUM;i++)
    {
        if(m_bullets[i].m_freeb)
        {
            m_bullets[i].m_freeb=false;

            m_bullets[i].m_xb=m_x+m_rect.width()*0.7;
            m_bullets[i].m_yb=m_y-10;
            break;
        }
    }

}

void myplane::setPosition(int x, int y)
{
    m_x=x;
    m_y=y;
    m_rect.moveTo(m_x,m_y);
}
